<?php
/***********************************************
 *      yaf 框架扩展类演示
 * 文件: /controller/Test.php
 * 说明: yaf 框架扩展类演示
 * 作者: Myxf
 * 更新: 2015年5月15日
 ***********************************************/

/**
 * yaf 框架扩展类演示
 */
class TestController extends Yaf_Controller_Abstract {

    private $_layout;

    public function init(){
        $this->_layout = Yaf_Registry::get('layout');
    }

    //默认入口
    public function indexAction(){
        echo "hello world!";
        return false;
    }

    //令牌登录
    public function loginAction(){
        $qrcode = new QRcode();
        $Google2FA = new Google2FA();
        $pid = $Google2FA->make_key();
        $_SESSION['pid'] = $pid;
        $qrcode->img('otpauth://totp/mayoushang?secret='.$pid);
        return false;
    }
    //验证令牌
    public function loginckAction(){
        $Google2FA = new Google2FA();
        if ($Google2FA->check_key($_SESSION['pid'], Fun::getg("pid"))){
          echo "ok";
        }else{
          echo "err";
        }
        return false;
    }

	//发送邮件类
    public function emailAction(){
        $email = new Mail();
        $emailto = array("address"=>"myxfonline@qq.com");
        $email->sendTextMail("nihao",$emailto,"372303586@qq.com","myxf","test");
        return false;
    }

    //文件上传类演示
    public function uploadAction(){
        $upload = new spUploadFile();
        echo $upload->upload_file($_FILES['pic'],"jpg|png|gif");
        return false;
    }

    //验证码生产类
    public function codeAction(){
        $captcha = new Captcha();
        $captcha->generate(4);
        return false;
    }
    //验证验证码
    public function _codeAction(){
        $captcha = new Captcha();
        echo $_SESSION['captcha'];
        return false;
    }

    //常用函数扩展类演示
    public function funAction(){
        $fun = new Tools();
        echo $fun->getRandom(1000,9999);
        echo $fun->strCut("1111@2222*3333","@","*");
        return false;
    }

    //定义url
    public function urlAction(){
        echo Url("main","show");
        //smarty中 {spUrl c=main a=show}
        echo spUrl("guestbook","page", array("gid"=>"3", "myname"=>"jake"));
        //smarty中 {spUrl c=guestbook a=page gid=3 myname="jake"}
        return false;
    }

    //http请求类
    public function httpAction(){
        $http = new spHttp();
        //get方法
        echo $http->vget("http://www.baidu.com/");
        //post方法
        echo $http->vpost("https://www.baidu.com/s","wd=324");
        return false;
    }

    //二维码生成类
    public function qrcodeAction(){
        ob_start();
        ob_clean();
        $qrcode = new QRcode();
        $qrcode->img("http://www.speedphp.com"); // 手机扫描后会得到网址
        //$qrcode->img("http://www.speedphp.com", "文件路径.png"); // 会生成PNG图片文件
        return false;
    }

    //xml解析类
    public function xmlAction(){
        $x=new spXml();
        $x->name = "my";
        $x->age='11';
        echo $x->xml();
        return false;
    }

    //zip操作类
    public function zipAction(){
        $zip = new PclZip();
        return false;
    }

    //表达数据验证类
    public function valAction(){
        $zip = new Validate();
        return false;
    }
    

}
